#! /usr/bin/env python

"""
::BOH
$Id: sensorgen.py,v 1.2 2006/04/30 00:30:00

Copyright (c) 2006 George Bobeck. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
::EOH

Creates the sensors.conf file for OWTF monitor.
"""
import sys, ow

OWsource = sys.argv[ 1 ]

f = open('sensors.conf','a+')
a = f.readlines()
fl = []
for e in a:
    if "#" not in e:
        e = e.strip('\n')
        e2 = e.split('\t')
        fl.append(e2[0])

def tree( sensor ):
    for next in sensor.sensors( ):
        if next._type in [ 'DS2409', ]:
            tree( next )
        else:
            # If sensor is not in sensors.conf, add it
            if next.address not in fl:
                sout='%s\tUnknown\n' % ( next.address )
                f.writelines(sout)
                f.flush()
            # sensor present, ignore it
            else:
                pass

if __name__ == "__main__":
    if len( OWsource ) == 1:
        print 'Error!'
        f.close()
        sys.exit( 1 )
    else:
        ow.init( OWsource )
        tree( ow.Sensor( '/' ) )
